﻿# CMakeList.txt : CMake project for prolab, include source and define
# project specific logic here.
#待测试link——dictenerory是否有用

#必须要设置在本CMakeLists.txt中
set(CMAKE_PREFIX_PATH ${QT_PREFIX_PATH})

set(CMAKE_INCLUDE_CURRENT_DIR ON)
#添加QT包
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Core  OpenGL  Gui REQUIRED)

#添加ui文件
file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} form/*.ui)
#添加资源文件
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} res/*.qrc)
#添加头文件
file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/*.h)

foreach(name IN LISTS QT_MOC)
        MESSAGE( STATUS "QT_MOC = ${name}.")
endforeach()

#添加源文件
file(GLOB_RECURSE PROJECT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/*.cpp)


#添加BOOST包！！！！！！CGAL库只需要Boost的头文件包含
set(BOOST_ROOT ${THIRDPARTY_PATH}/boost_1_68_0)
set(Boost_NO_SYSTEM_PATHS ON)
find_package(Boost 1.68.0 REQUIRED)
if(Boost_FOUND)
    MESSAGE( STATUS "Boost Successfully found.")
    MESSAGE( STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}.")
    MESSAGE( STATUS "Boost_LIB_VERSION = ${Boost_LIB_VERSION}.")
endif()

#添加CGAL包
set(CGAL_DIR ${THIRDPARTY_PATH}/CGAL/dev/CGAL-4.14.3/)
find_package(CGAL REQUIRED)
MESSAGE( STATUS "CGAL_INCLUDE_DIRS = ${CGAL_INCLUDE_DIRS}.")
MESSAGE( STATUS "CGAL_LIBRARIES = ${CGAL_LIBRARIES}.")

#添加Gmp
set(GMP_LIB_PATH ${CGAL_DIR}/auxiliary/gmp/lib)
link_directories(${GMP_LIB_PATH})
#注意file的用法，以下文命令为例，在“${GMP_LIB_PATH}”目录中筛选*.lib文件（绝对路径），
#删除先前得到的绝对路径列表元素中的“${GMP_LIB_PATH}”文本，获得相对路径，保存到GMP_LIB中
file(GLOB GMP_LIB RELATIVE ${GMP_LIB_PATH} ${GMP_LIB_PATH}/*.lib)
link_libraries(${GMP_LIB})
MESSAGE( STATUS "GMP_LIB = ${GMP_LIB}.")


#添加opencv包
set(OpenCV_DIR ${THIRDPARTY_PATH}/opencv/build/x64/vc15/lib)
#一般而言，find_package仅仅是找到对应的XXXConfig.cmake文件，获取对应的信息（静态库/动态库/头文件 列表保存到指定变量中）
#需要手动链接/包含指定变量，OpenCV就是典型的例子，找到OpenCVConfig.cmake文件之后，
#获得了存储头文件的OpenCV_INCLUDE_DIRS和静态库的OpenCV_LIBRARIES变量
#需要手动使用include_directories/target_link_libraries添加。
#但也有部分库，库的提供者已经做好了这部分工作（例如Qt）
find_package(OpenCV REQUIRED)
MESSAGE( STATUS "OpenCV_INCLUDE_DIRS = ${OpenCV_INCLUDE_DIRS}.")
MESSAGE( STATUS "OpenCV_LIBRARIES = ${OpenCV_LIBRARIES}.")

#添加nlopt包
link_directories(${NLOPT_PATH}/bin)
file(GLOB NLOPT_DBG_LIB RELATIVE ${NLOPT_PATH}/bin/Debug ${NLOPT_PATH}/bin/Debug/*.lib)
file(GLOB NLOPT_REL_LIB RELATIVE ${NLOPT_PATH}/bin/Release ${NLOPT_PATH}/bin/Release/*.lib)
MESSAGE( STATUS "NLOPT_DBG_LIB = ${NLOPT_DBG_LIB}.")
MESSAGE( STATUS "NLOPT_REL_LIB = ${NLOPT_REL_LIB}.")

#链接Matlab静态库
    set(MATLAB_LIB_PATH ${MATLAB_PREFIX_PATH}/lib/win64/microsoft)
    link_directories(${MATLAB_LIB_PATH})
    file(GLOB MATLAB_LIB RELATIVE ${MATLAB_LIB_PATH} ${MATLAB_LIB_PATH}/*.lib)
    link_libraries(${MATLAB_LIB})
#链接OSG静态库
    link_directories(${OSG_PREFIX_PATH})
    file(GLOB OSG_DBG_LIB RELATIVE ${OSG_PREFIX_PATH}/Debug ${OSG_PREFIX_PATH}/Debug/*.lib)
    file(GLOB OSG_REL_LIB RELATIVE ${OSG_PREFIX_PATH}/Release ${OSG_PREFIX_PATH}/Release/*.lib)
    MESSAGE( STATUS "OSG_DBG_LIB = ${OSG_DBG_LIB}.")
    MESSAGE( STATUS "OSG_REL_LIB = ${OSG_REL_LIB}.")

#链接PCL静态库
    link_directories(${PCL_PREFIX_PATH})
    file(GLOB PCL_DBG_LIB RELATIVE ${PCL_PREFIX_PATH}/Debug ${PCL_PREFIX_PATH}/Debug/*.lib)
	file(GLOB PCL_REL_LIB RELATIVE ${PCL_PREFIX_PATH}/Release ${PCL_PREFIX_PATH}/Release/*.lib)
    MESSAGE( STATUS "PCL_DBG_LIB = ${PCL_DBG_LIB}.")
    MESSAGE( STATUS "PCL_REL_LIB = ${PCL_REL_LIB}.")

#链接geomlib静态库
    link_directories(${GEPMLIB_PATH})
    file(GLOB GEOM_DBG_LIB RELATIVE ${GEPMLIB_PATH}/Debug ${GEPMLIB_PATH}/Debug/*.lib)
	file(GLOB GEOM_REL_LIB RELATIVE ${GEPMLIB_PATH}/Release ${GEPMLIB_PATH}/Release/*.lib)
    MESSAGE( STATUS "GEOM_DBG_LIB = ${GEOM_DBG_LIB}.")
    MESSAGE( STATUS "GEOM_REL_LIB = ${GEOM_REL_LIB}.")

# 添加资源、UI和MOC文件
QT5_ADD_RESOURCES(QT_RESOURCES_FILES ${QT_RESOURCES})
QT5_WRAP_UI(QT_FORMS_FILES ${QT_FORMS})
QT5_WRAP_CPP(QT_MOC_FILES ${QT_MOC})

# 添加可执行文件！！！！！！各个编译器转换之后，.h文件识别为头文件，.cpp文件识别为源文件
#（以msvc为例，.h,.cpp会在sln文件资源浏览器窗格展示）
#注意！！！！以${QT_MOC}为例，${QT_MOC}中的文件名要么是绝对路径要么是相对当前CMakeLists.txt所在目录的相对路径
#add_executable文件如果有头文件，不会自动起到link_directories和target_link_directorios的作用
add_executable(ProLab
    ${QT_RESOURCES_FILES}
    ${QT_MOC_FILES}
	${QT_MOC}
    ${PROJECT_SOURCES}
    ${QT_FORMS_FILES}
)

# 设置可执行文件的输出路径（的影响范围可以自定义。如加关键子PRIVATE或这PUBLIC）
#！！！！！！这个命令一般用在子目录，
#用于设置全局变量（以msvc为例，.h,.cpp不会在sln文件资源浏览器窗格展示，仅作为头文件）
SET(EXECUTABLE_OUTPUT_PATH ${PROLAB_OUTPUT_PATH})

# 设置编译选项
target_compile_options(ProLab 
    PRIVATE 
    $<$<CXX_COMPILER_ID:MSVC>:/bigobj> 
    $<$<CXX_COMPILER_ID:GNU>:-Wa,-mbig-obj>)

#添加头文件
target_include_directories(ProLab PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(ProLab PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/FEA_2D)
target_include_directories(ProLab PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/FEA_3D)
target_include_directories(ProLab PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/GraFillPath)
target_include_directories(ProLab PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/OffsetPath)
target_include_directories(ProLab PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/RefSurfSlice)
target_include_directories(ProLab PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/RobotSimu)
target_include_directories(ProLab PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/TopoOptimize_2D)
target_include_directories(ProLab PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/TopoOptimize_3D)
target_include_directories(ProLab PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/VecFieldPath)
target_include_directories(ProLab PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/VecSurfSlice)

target_include_directories(ProLab PRIVATE ${Boost_INCLUDE_DIRS})
target_include_directories(ProLab PRIVATE ${CGAL_INCLUDE_DIRS})
target_include_directories(ProLab PRIVATE ${OpenCV_INCLUDE_DIRS})

# 链接静态库
foreach(name ${OSG_DBG_LIB})
    target_link_libraries(ProLab PRIVATE debug ${name})
    MESSAGE( STATUS "link !!osg debug lib : ${name}.")
endforeach(name)
foreach(name ${PCL_DBG_LIB})
    target_link_libraries(ProLab PRIVATE debug ${name})
    MESSAGE( STATUS "link pcl debug lib : ${name}.")
endforeach(name)
foreach(name ${NLOPT_DBG_LIB})
    target_link_libraries(ProLab PRIVATE debug ${name})
    MESSAGE( STATUS "link nlopt debug lib : ${name}.")
endforeach(name)
foreach(name ${GEOM_DBG_LIB})
    target_link_libraries(ProLab PRIVATE debug ${name})
    MESSAGE( STATUS "link geomLIB debug lib : ${name}.")
endforeach(name)
foreach(name IN LISTS OSG_REL_LIB)
    target_link_libraries(ProLab PRIVATE optimized ${name})
    MESSAGE( STATUS "link !!osg release lib : ${name}.")
endforeach(name)
foreach(name IN LISTS PCL_REL_LIB)
    target_link_libraries(ProLab PRIVATE optimized ${name})
    MESSAGE( STATUS "link pcl release lib : ${name}.")
endforeach(name)
foreach(name IN LISTS NLOPT_REL_LIB)
    target_link_libraries(ProLab PRIVATE optimized ${name})
    MESSAGE( STATUS "link nlopt release lib : ${name}.")
endforeach(name)
foreach(name IN LISTS GEOM_REL_LIB)
    target_link_libraries(ProLab PRIVATE optimized ${name})
    MESSAGE( STATUS "link geomLIB release lib : ${name}.")
endforeach(name)

target_link_libraries(ProLab PRIVATE ${CGAL_LIBRARIES})
target_link_libraries(ProLab PRIVATE ${OpenCV_LIBRARIES})
#由于Qt的特殊设置，在应用下文命令时，就将对应的.h头文件包含到ProLab中了
target_link_libraries(ProLab PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(ProLab PRIVATE Qt${QT_VERSION_MAJOR}::Core)
target_link_libraries(ProLab PRIVATE Qt${QT_VERSION_MAJOR}::OpenGL)
target_link_libraries(ProLab PRIVATE Qt${QT_VERSION_MAJOR}::Gui)
file(COPY ${BIN_NEED_PATH}/debug/ DESTINATION ${EXECUTABLE_OUTPUT_PATH}/Debug/)
file(COPY ${BIN_NEED_PATH}/release/ DESTINATION ${EXECUTABLE_OUTPUT_PATH}/Release/)
#why????父目录中不起作用，这里起作用
file(COPY ${THIRDPARTY_PATH}/axes/ DESTINATION ${EXECUTABLE_OUTPUT_PATH}/Debug/)
file(COPY ${THIRDPARTY_PATH}/axes/ DESTINATION ${EXECUTABLE_OUTPUT_PATH}/Release/)
